home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / LIB / MTHERR.C < prev    next >
C/C++ Source or Header  |  1995-12-01  |  3KB  |  106 lines

  1. /*                            mtherr.c
  2.  *
  3.  *    Library common error handling routine
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * char *fctnam;
  10.  * int code;
  11.  * void mtherr();
  12.  *
  13.  * mtherr( fctnam, code );
  14.  *
  15.  *
  16.  *
  17.  * DESCRIPTION:
  18.  *
  19.  * This routine may be called to report one of the following
  20.  * error conditions (in the header file mconf.h).
  21.  *
  22.  *   Mnemonic        Value          Significance
  23.  *
  24.  *    DOMAIN            1       argument domain error
  25.  *    SING              2       function singularity
  26.  *    OVERFLOW          3       overflow range error
  27.  *    UNDERFLOW         4       underflow range error
  28.  *    TLOSS             5       total loss of precision
  29.  *    PLOSS             6       partial loss of precision
  30.  *    EDOM             33       Unix domain error code
  31.  *    ERANGE           34       Unix range error code
  32.  *
  33.  * The default version of the file prints the function name,
  34.  * passed to it by the pointer fctnam, followed by the
  35.  * error condition.  The display is directed to the standard
  36.  * output device.  The routine then returns to the calling
  37.  * program.  Users may wish to modify the program to abort by
  38.  * calling exit() under severe error conditions such as domain
  39.  * errors.
  40.  *
  41.  * Since all error conditions pass control to this function,
  42.  * the display may be easily changed, eliminated, or directed
  43.  * to an error logging device.
  44.  *
  45.  * SEE ALSO:
  46.  *
  47.  * mconf.h
  48.  *
  49.  */
  50. /* -------------------------------------------------------------------- */
  51. /*
  52. Cephes Math Library Release 2.0:  April, 1987
  53. Copyright 1984, 1987 by Stephen L. Moshier
  54. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  55. */
  56. #include <stdio.h>
  57. #include "mconf.h"
  58.  
  59. /* Notice: the order of appearance of the following
  60.  * messages is bound to the error codes defined
  61.  * in mconf.h.
  62.  */
  63. static char *ermsg[7] = {
  64. "unknown",      /* error code 0 */
  65. "domain",       /* error code 1 */
  66. "singularity",  /* et seq.      */
  67. "overflow",
  68. "underflow",
  69. "total loss of precision",
  70. "partial loss of precision"
  71. };
  72.  
  73.  
  74. # if defined(__STDC__) || defined(__PROTO__)
  75. void
  76. mtherr(char *name, int code)
  77. # else
  78. void
  79. mtherr(name, code)
  80. char   *name;
  81. int    code;
  82. # endif
  83. {
  84. char    *ErrStr;
  85. /* Display string passed by calling program,
  86.  * which is supposed to be the name of the
  87.  * function in which the error occurred:
  88.  */
  89. printf( "\n%s: ", name );
  90.  
  91. /* Display error message defined
  92.  * by the code argument.
  93.  */
  94.  
  95. ErrStr = (code < 0)      ? ermsg[0]    :
  96.      (code <= 6)      ? ermsg[code] :
  97.      (code == EDOM)   ? "DOMAIN"    :
  98.      (code == ERANGE) ? "RANGE"    : ermsg[0];
  99.  
  100. printf( "%s error\n", ErrStr );
  101.  
  102. /* Return to calling
  103.  * program
  104.  */
  105. }
  106.